package com.ruoyi.web.controller.Commerce.members;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChamberApplication;
import com.ruoyi.system.service.IChamberApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log;

/**
 * 商会成员入会申请Controller
 * 
 * @author ruoyi
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/system/application")
public class ChamberApplicationController extends BaseController
{
    @Autowired
    private IChamberApplicationService chamberApplicationService;

    /**
     * 查询商会成员入会申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChamberApplication chamberApplication)
    {
        startPage();
        List<ChamberApplication> list = chamberApplicationService.selectChamberApplicationList(chamberApplication);
        return getDataTable(list);
    }

    /**
     * 导出商会成员入会申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:application:export')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChamberApplication chamberApplication)
    {
        List<ChamberApplication> list = chamberApplicationService.selectChamberApplicationList(chamberApplication);
        ExcelUtil<ChamberApplication> util = new ExcelUtil<ChamberApplication>(ChamberApplication.class);
        util.exportExcel(response, list, "商会成员入会申请数据");
    }

    /**
     * 获取商会成员入会申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:application:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(chamberApplicationService.selectChamberApplicationById(id));
    }

    /**
     * 新增商会成员入会申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:add')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChamberApplication chamberApplication)
    {
        return toAjax(chamberApplicationService.insertChamberApplication(chamberApplication));
    }

    /**
     * 修改商会成员入会申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:edit')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChamberApplication chamberApplication)
    {
        return toAjax(chamberApplicationService.updateChamberApplication(chamberApplication));
    }

    /**
     * 删除商会成员入会申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:remove')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(chamberApplicationService.deleteChamberApplicationByIds(ids));
    }

    //商会通过成员的入会申请
    @PreAuthorize("@ss.hasPermi('system:application:approve')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.UPDATE)
    @PutMapping("/approve")
    public AjaxResult approve(@RequestBody Integer[] ids) {
        return toAjax(chamberApplicationService.approveChamberApplicationByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('system:application:reject')")
    @Log(title = "商会成员入会申请", businessType = BusinessType.UPDATE)
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody Integer[] ids) {
        return toAjax(chamberApplicationService.rejectChamberApplicationByIds(ids));
    }
}
